package com.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONWriter;
import com.dao.OrderMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.model.AppSystem;
import com.model.FspAppSystem;
import com.service.CirDeService;
import com.service.CirDeService1;
import com.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.support.AopUtils;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * @ Author xsd
 * @ crate time 2020/5/26 9:43
 * @ 描述
 */
//@Component
@Controller
@RequestMapping(value = "/info")
@Slf4j
public class TestController {
    private List<String> list=new ArrayList<>();

    @Resource
    private OrderMapper orderMapper;
    @Resource
    private OrderService orderService;
    @Resource
    private CirDeService cirDeService;
    @Resource
    private CirDeService1 cirDeService1;

    @RequestMapping(value="/get",produces = "text/html;charset=utf-8")
    @ResponseBody
    public String select(){
        list.add("23232");
        log.info("come in....");
        List<AppSystem> map= orderMapper.queryAll();
        return JSON.toJSONString(map);
    }

    @RequestMapping(value="/list")
    @ResponseBody
    public String list(){
        List<AppSystem> map= orderService.queryAll();
        return JSON.toJSONString(map);
    }

    @RequestMapping(value="/insert")
    @ResponseBody
    public String insert(String name) throws Exception{
        log.info("come in....");
        FspAppSystem f=new FspAppSystem();
        f.setId(UUID.randomUUID().toString());
        int result= orderService.insertS(f);
        return JSON.toJSONString(result);
    }

    @RequestMapping(value="/pageGet")
    @ResponseBody
    public String pageGet(){
        log.info("come in....");
//        PageHelper.offsetPage(1,3);
        PageHelper.startPage(1,3);
        List<AppSystem> list= orderMapper.queryAll();
        PageInfo<AppSystem> pageInfo = new PageInfo<AppSystem>(list);
        long total = pageInfo.getTotal(); //获取总记录数
        System.out.println("总共数据有：" + total);
        return JSON.toJSONString(total);
    }

    @RequestMapping(value="/del")
    @ResponseBody
    public String insert() throws Exception{
        orderService.delete("222222222");
        return "";
    }
}
